/* 
 * File:   Light.h
 * Author: gilvolpe
 *
 * Created on June 7, 2013, 8:51 PM
 */

#ifndef LIGHT_H
#define	LIGHT_H

#include "basicInformation.h"

class Light {
public:

    Light(
            GLenum lightID = GL_LIGHT0
            , float spotExponent = 0.0
            , float spotCutoff = 180.0f
            , float constantAttenuation = 1.0
            , float linearAttenuation = 0.0
            , float quadraticAttenuation = 0.0
            )
    : m_LightID(lightID)
    , m_SpotExponent(spotExponent)
    , m_SpotCutoff(spotCutoff)
    , m_ConstantAttenuation(constantAttenuation)
    , m_LinearAttenuation(linearAttenuation)
    , m_QuadraticAttenuation(quadraticAttenuation) {

        m_Position[0] = 0.0f;
        m_Position[1] = 0.0f;
        m_Position[2] = 0.0f;
        m_Position[3] = 100000000.0f;

        m_Ambient[0] = 0.1f;
        m_Ambient[1] = 0.1f;
        m_Ambient[2] = 0.1f;
        m_Ambient[3] = 0.1f;

        m_Diffuse[0] = 1.0f;
        m_Diffuse[1] = 1.0f;
        m_Diffuse[2] = 1.0f;
        m_Diffuse[3] = 0.0f;

        m_Specular[0] = 1.0f;
        m_Specular[1] = 1.0f;
        m_Specular[2] = 1.0f;
        m_Specular[3] = 0.0f;

        m_SpotDirection[0] = 0.0f;
        m_SpotDirection[1] = 0.0f;
        m_SpotDirection[2] = -1.0f;

        flat = true;

    }

    void changeShadding() {
        flat = !flat;
    }

    void Activate() {

        glPushMatrix();

        if (flat)
            glShadeModel(GL_FLAT);
        else
            glShadeModel(GL_SMOOTH);

        glEnable(m_LightID);
        glLightfv(m_LightID, GL_AMBIENT, m_Ambient);
        glLightfv(m_LightID, GL_DIFFUSE, m_Diffuse);
        glLightfv(m_LightID, GL_SPECULAR, m_Specular);

        glLightfv(m_LightID, GL_POSITION, m_Position);

        glLightfv(m_LightID, GL_SPOT_DIRECTION, m_SpotDirection);
        glLightf(m_LightID, GL_SPOT_EXPONENT, m_SpotExponent);
        glLightf(m_LightID, GL_SPOT_CUTOFF, m_SpotCutoff);
        glLightf(m_LightID, GL_CONSTANT_ATTENUATION, m_ConstantAttenuation);
        glLightf(m_LightID, GL_LINEAR_ATTENUATION, m_LinearAttenuation);
        glLightf(m_LightID, GL_QUADRATIC_ATTENUATION, m_QuadraticAttenuation);


        glPopMatrix();
    }

    void Deactivate() {
        glDisable(m_LightID);
    }
private:
    GLenum m_LightID;

    float m_Ambient[4];
    float m_Diffuse[4];
    float m_Specular[4];
    float m_Position[4];
    float m_SpotDirection[3];

    float m_SpotExponent;
    float m_SpotCutoff;
    float m_ConstantAttenuation;
    float m_LinearAttenuation;
    float m_QuadraticAttenuation;

    bool flat;
};

#endif	/* LIGHT_H */

